package com.qf.crm.service.impl;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import com.qf.crm.dao.CustomerDao;
import com.qf.crm.dao.impl.CustomerDaoImpl;
import com.qf.crm.entity.Customer;
import com.qf.crm.service.CustomerService;
import com.qf.crm.utils.JdbcUtils;

public class CustomerServiceImpl implements CustomerService{

	private CustomerDao customerDao = new CustomerDaoImpl();
	
	@Override
	public List<Customer> getCustomerList() {
		Connection connection = null;
		try {
			connection = JdbcUtils.getConnection();
			connection.setAutoCommit(false);
			String sql="SELECT customer_id as customerId,customer_name as customerName,phone,`status`,person_liable_id as personLiableId,founder_id as founderId,source_id as sourceId,industry_id as industryId,level_id as levelId,create_time as createTime,update_time as updateTime,next_contact_time as nextContactTime,flag FROM customer";
			List<Customer> list = customerDao.getCustomerList(connection, sql, Customer.class);
			connection.commit();
			return list;
		} catch (InstantiationException | IllegalAccessException | NoSuchFieldException | SecurityException
				| SQLException e) {
			if(connection!=null) {
				try {
					connection.rollback();
				} catch (SQLException e1) {
					e1.printStackTrace();
				}
			}
			e.printStackTrace();
		}finally {
			JdbcUtils.close();
		}
		return null;
	}

}
